﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Ay.Framework.WPF.Controls;
using Ay.MvcFramework.Wpf;
using System.IO;
using System.Windows.Media;
using System.Threading;
using System.Diagnostics;
using System.Windows.Forms;
using System.Windows.Interop;
using System;
using Hotel.UI.Common;

namespace Hotel.UI.Views
{
    /// <summary>
    /// ImageViewer.xaml 的交互逻辑
    /// </summary>
    public partial class ImageViewer : AyWindow
    {
        public ImageViewer()
        {
            InitializeComponent();
            this.CloseIsHideWindow = false;
            AyExtension.SetAyWindowMouseLeftButtonMove(this, this.gridHeaderBar);

            this.Loaded += ImageViewer_Loaded;


            //this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
            //this.MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;

            this.LocationChanged += (ss, ee) =>
            {
                Debug.WriteLine($"=={ee}=");
                SetMaxSize();
            };
        }
        public void SetMaxSize()
        {
            return;
            var sc = GetCurrentScreen();

            if (sc != null && sc.DeviceName != screenName)
            {
                this.MaxHeight = sc.WorkingArea.Height;
                this.MaxWidth = sc.WorkingArea.Width;
                screenName = sc.DeviceName;
            }

            Debug.WriteLine($"==========={SystemParameters.MaximizedPrimaryScreenWidth}==={SystemParameters.MaximizedPrimaryScreenHeight}======================");
            Debug.WriteLine($"==========={sc.Primary}==={sc.Bounds.Width}=={sc.Bounds.Height}==={sc.DeviceName}====================");

        }
        string screenName = "";
        private Screen GetCurrentScreen()
        {
            IntPtr handle = new WindowInteropHelper(this).Handle;
            return System.Windows.Forms.Screen.FromHandle(handle);
        }

        private void ImageViewer_Loaded(object sender, RoutedEventArgs e)
        {
            SetMaxSize();
            var dpi = VisualTreeHelper.GetDpi(this);
            DoWork(dpi);
            //new Task(() => DoWork(dpi)).Start();
        }
        ObservableCollection<AyImageListItemFromByte> lists = new ObservableCollection<AyImageListItemFromByte>();

        private void DoWork(DpiScale dpi)
        {

            //var baseUri = System.IO.Path.Combine(AyuiConfig.ApplicationDirectory, @"Contents/Images/DemoImage/");
            //List<string> uris = new List<string>
            //{
            //      baseUri + "44307-106.jpg",
            //      baseUri + "21313-106.jpg",
            //     baseUri + "98913-106.jpg",
            //     baseUri + "17166-106.jpg",
            //     //baseUri + "131098-106.jpg",
            //     baseUri + "331529-106.jpg",
            //     baseUri +"47494-106.jpg",
            //     baseUri + "42197-106.jpg",
            //     baseUri + "99138-106.jpg",
            //     baseUri + "122043-106.jpg",
            //     baseUri + "278659-106.jpg"
            //};
            //string f = null;
            string folderPath = "C:\\Users\\Admin\\Pictures";
            DirectoryInfo di = new DirectoryInfo(folderPath);
            //FileInfo[] files = folder.GetFiles("*.*", SearchOption.AllDirectories);
            FileInfo[] files = di.GetFiles("*.bmp")
                                    .Union(di.GetFiles("*.jpg"))
                                    .Union(di.GetFiles("*.png"))
                                    .Union(di.GetFiles("*.jpeg"))
                                    .Union(di.GetFiles("*.tiff"))
                                    .Union(di.GetFiles("*.webp"))
                                    .ToArray();
            foreach (FileInfo file in files)
            {
                AyImageListItemFromByte b1 = new AyImageListItemFromByte();
                //b1.ImageByte = ImageResources.GetImageByteByUri(file.FullName);
                //b1.ImgSource = ImageResources.GetImageSource(dpi, file.FullName);
                b1.FileName = AyCommon.GetGuidNoSplit;

                lists.Add(b1);
            }


            //var backColor = System.Drawing.ColorTranslator.FromHtml("#037be2");
            //var forColor = System.Drawing.ColorTranslator.FromHtml("#ffffff");

            //img.Source = FancyText.BitmapImageFromText("相册编排", new System.Drawing.Font("Microsoft YaHei", 10, System.Drawing.FontStyle.Bold), forColor, backColor, 6);
            //img1.Source = FancyText.BitmapImageFromText("外发光+描边", new System.Drawing.Font("Microsoft YaHei", 30, System.Drawing.FontStyle.Bold), forColor, backColor, 3); 


            // 使用Dispatcher更新UI
            this.Dispatcher.Invoke(() =>
            {
                allBrowser.ItemsSource = lists;

            });
        }
    }

}
